<?php
class AjaxController extends Controller
{
    function showIndex()
    {
        die("sss");
        // TODO: Implement showIndex() method.
    }

    function isLogin()
    {
        $this->ajaxRender($this->checkIsLogin() && !$this->isAdmin() ? "1" : "0");
    }

    function voteActivity()
    {
        if ($this->checkIsLogin() && !$this->isAdmin()) {
            if ($this->checkIdFromGet("activityId")) {
                $this->ajaxRender($this->modules->Activity->doVote($this->_get['activityId'], $this->getCredentials('userId'), $this->getClientIp()));
            }
        }
        else
        {
            $this->ajaxRender("投票失败，请登录");
        }

    }

    function voteApplication()
    {
        $operatorId = $this->_get['operatorId'];
        $operatedId = $this->_get['operatedId'];
        /*  if (!$this->modules->Log->isIpExist($operatorId, $this->getClientIp(), "VOTE")) {*/
        $this->modules->Log->insert($operatorId, $operatedId, $this->getClientIp(), "VOTE");
        $this->modules->UserVote->vote($operatorId, $operatedId);
        $this->ajaxRender("投票成功,谢谢您的参与");
        /*  }
        else
        {
            $this->ajaxRender("对不起，每人只能限投一次,感谢您的参与");
        }*/
    }

    function upload()
    {
        include_once(ROOT . "/lib/Upload.class.php");
        // list of valid extensions, ex. array("jpeg", "xml", "bmp")
        $allowedExtensions = array("jpg", "png", "gif");
        // max file size in bytes
        $sizeLimit = 2 * 1024 * 1024;

        $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
        $result = $uploader->handleUpload(ROOT, '/uploads/', false, DOMAIN);
        // to pass data through iframe you will need to encode all html tags
        echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
    }

    function currentUser()
    {
        $this->ajaxRender(json_encode($_SESSION['credentials']));
    }

    function checkUserNameRegister()
    {
        $userName = $this->_get['userName'];
        if ($this->modules->User->canUserNameRegistered($userName)) {
            $this->ajaxRender("1");
        }
        else

        {
            $this->ajaxRender("0");
        }
    }

}

?>